//
//  ViewController.m
//  易车界面
//
//  Created by dllo on 16/7/27.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "CarTableViewCell.h"
#import "CarViewModel.h"

#define kCell_CarReuseIdentifier @"CarTableViewCell"

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *bodyDataArr;
@property (nonatomic, strong) NSMutableArray *headDataArr;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTableView];
    
    // 得到数据
    CarViewModel *vm = [[CarViewModel alloc]init];
    __block NSMutableArray *bodyDataArr;
    __block NSMutableArray *headDataArr;
    [vm getData:^(NSArray *headArr, NSArray *bodyArr) {
        bodyDataArr = bodyArr.mutableCopy;
        headDataArr = headArr.mutableCopy;
    }];
    _headDataArr = headDataArr;
    _bodyDataArr = bodyDataArr;
}

- (void)createTableView
{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 10) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.dataSource = self;
    _tableView.delegate = self;
    
    [_tableView registerClass:[CarTableViewCell class] forCellReuseIdentifier:kCell_CarReuseIdentifier];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    }
    return _bodyDataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CarTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCell_CarReuseIdentifier];
    if (indexPath.section == 0) {
        return nil;
    }
    cell.model = _bodyDataArr[indexPath.row];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 110;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
